package study.javaee.practice.dao;

import study.javaee.practice.entity.JpaProject;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface JpaProjectDAO extends JpaRepository<JpaProject,Integer> {

    @Query("select p from JpaProject p where p.name = ?1")
    JpaProject findByName(String name);

    @Query("select p from JpaProject p where p.leaderId = ?1")
    JpaProject getByleaderId(int leaderId);

    @Query("select p from JpaProject p where p.unitId = ?1")
    JpaProject getByunitId(int unitId);

    @Modifying
    @Query("delete from JpaProject p where p.id = ?1")
    JpaProject deleteById(int id);

    @Query("select name,unitId,leaderId,createTime,finishTime,state from JpaProject where leaderId =?1")
    List<Object> find_Jpql_list_morefield(int lid);

    @Query("select p.name,u1.name,u2.name,p.createTime,p.finishTime,p.state from JpaProject p,JpaUnit u1,JpaMd5user u2 where p.unitId=u1.id and p.leaderId=u2.id and p.state=?1")
    List<Object> find_Jpql_list_morefield_byState(int state);

    @Query("select p.name,u1.name,u2.name,p.createTime,p.finishTime,p.state from JpaProject p,JpaUnit u1,JpaMd5user u2 where p.unitId=u1.id and p.leaderId=u2.id and p.leaderId=?1")
    List<Object> findJoinByLeaderId(int leaderId);

}
